const app = getApp();
Component({
  options: {
    addGlobalClass: true,
  },
  data: {
    CustomBar: app.globalData.CustomBar,
    list:[],
    icon:"",
    swiperList: [{
      id: 0,
      type: 'image',
      url: 'https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=1380304390,3321739249&fm=26&gp=0.jpg'
    }, {
      id: 1,
      type: 'image',
        url: 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1606747153332&di=912684db982d2a188473e7c578b883eb&imgtype=0&src=http%3A%2F%2Fgss0.baidu.com%2F-vo3dSag_xI4khGko9WTAnF6hhy%2Fzhidao%2Fpic%2Fitem%2F0e2442a7d933c8954c08ed35dc1373f08202000d.jpg',
      }, {
        id: 2,
        type: 'image',
        url: 'https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=2808483794,1634552892&fm=26&gp=0.jpg',
      }],
  },
  //自定义组件
  attached: function () {
    var that = this;
    getData(that,"")
    

  }, methods: {
   shouchang(e) {
      console.log("sssssssssssss");
    if (!app.globalData.isLogin) {
      wx.navigateTo({
        url: '/pages/about/login/login' 
        })

    }else{
      var that = this;
      var id = e.currentTarget.dataset.id;
      var Collection = app.globalData.local_url + "api/collection" ;
      wx.request({
        url: Collection,
        data: {
          newsId:id,
          userId:app.globalData.userId
        },
        method: 'POST',
        header: {
          'content-type': 'application/json'
        },
        success: function (res) {
          if (res.data.code == 200) {
            console.log(res.data.data);
            getData(that, "");
    
          } 
        }
      })
    }
  },
    getData(e) {

      var that = this;

      that.setData({
        icon: app.globalData.local_url,
      })

      var val = e.detail.value;
     
    
      getData(that, val);
    }, toReply(e) {
      var id = e.currentTarget.dataset.id;
      app.globalData.id = id;
      wx.navigateTo({
        url: '/pages/basics/detailed/detailed?id=' + id
      })

    }


  }




})


function getData(that,val){

  var get_url = app.globalData.local_url + "api/getNewList?name="+val+"&type=1&userId="+app.globalData.userId ;
  
  wx.request({
    url: get_url,
    data: {

    },
    method: 'POST',
    header: {
      'content-type': 'application/json'
    },
    success: function (res) {
      if (res.data.code == 200) {
        console.log(res.data.data);
        that.setData({
          list: res.data.data,
        });

      } else {

      }
    }
  })


}